package cn.xy.mapper.impl;

import cn.xy.mapper.StudentMapper;
import cn.xy.pojo.Student;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

/**
 * 继承SqlSessionDaoSupport类
 * spring容器中set方式注入sqlSessionFactory属性
 * 就可以直接获取SqlSession了
 */
public class StudentMapperImpl extends SqlSessionDaoSupport implements StudentMapper {

    public List<Student> getStudentList() {
        return getSqlSession().getMapper(StudentMapper.class).getStudentList();
    }

    public Integer addStudent(Student student) {
        return getSqlSession().getMapper(StudentMapper.class).addStudent(student);
    }

    public Integer deleteStudent(int id) {
        return getSqlSession().getMapper(StudentMapper.class).deleteStudent(id);
    }

    public void transaction() {
        StudentMapper mapper = getSqlSession().getMapper(StudentMapper.class);
        mapper.addStudent(new Student(6,"小吴",1));
        int i = 1/0;
        mapper.deleteStudent(6);
    }
}
